{% extends "base.html" %}

{% block head %}
<script type="text/javascript"></script>

<script type="text/javascript">
  function loadScript(url, callback) {
      if (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) {
          var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(),
              time = false;

          xhr.onreadystatechange = function() {
            if (xhr.readyState==1 && !time)
              time = Number(new Date());

            if (xhr.readyState==4)
              callback(Number(new Date()) - time);
          }
          
          xhr.open("GET", url, true);
          xhr.send(null);        
      }
      else
      {
        var iframe = document.getElementsByTagName('iframe')[0],
            time = Number(new Date());

        iframe.onload = function(){
            callback(Number(new Date()) - time);
        };
        
        iframe.src = url;
      }
  }

  function loadAndExecuteScript(url, callback){
      var script = document.getElementsByTagName('script')[0];
      
      script.type = "text/javascript";

      if (script.readyState){  //IE
          script.onreadystatechange = function(){
              if (script.readyState == "loaded" ||
                      script.readyState == "complete"){
                  script.onreadystatechange = null;
                  callback(Number(new Date()) - t);
              }
          };
      } else {  //Others
          script.onload = function(){
              callback(Number(new Date()) - t);
          };
      }

      var t = Number(new Date());
      script.src = url;
  }
  
  window.onload = function() {
    
    loadScript("{{ placement.url }}?seed="+Math.random(), function(res) {
      if (window.parent && typeof window.parent.logResults != 'undefined')
        window.parent.logResults('{{ id }}', res);
    });

    // loadAndExecuteScript("{{ placement.url }}?seed="+Math.random(), function(res) {
    //   if (window.parent && typeof window.parent.logResults != 'undefined')
    //     window.parent.logResults('{{ id }}', res);
    // });
  }

</script>
{% endblock %}

{% block content %}
  <iframe></iframe>
{% endblock %}